<?php

namespace mpend\modules\user\models;

use Yii;

/**
 * 签到查询
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class SigninLogSearch extends \common\models\user\UserSigninLog {

    /**
     * @inheritdoc
     */
    public function buildQuery($alias = 't') {
        $query = static::find();
        if ($alias) {
            $query->alias($alias);
            $alias .= '.';
        }
        $query->andWhere([
            $alias . 'user_id' => $this->user_id,
        ]);
        $query->orderBy([
            $alias . 'date' => SORT_DESC,
        ]);
        $query->debug();
        return $query;
    }

    /**
     * @inheritdoc
     */
    public function fields() {
        return [
            'id',
            'user_id',
            'date',
            'location',
            'status' => function() {
                return $this->date == date('Y-m-d');
            },
        ];
    }

}
